﻿using System;
using System.Collections.Generic;
using System.Text;

namespace GTTSOfLibrary.Common
{
    /// <summary>
    /// 异常处理类
    /// </summary>
    public class ErrorHandler
    {
        /// <summary>
        /// 异常处理
        /// <example>
        /// 使用方法：
        /// <code>
        ///    try
        ///    {
        ///        //...code
        ///    }
        ///    catch (Exception ex)
        ///    {
        ///        ErrorHandler.OnError(ex);
        ///    }
        /// </code>
        /// </example>
        /// </summary>
        /// <param name="ex"></param>
        public static void OnError(Exception ex)
        {
            if (ex.GetType() == typeof(ApplicationException) || ex.GetType().IsSubclassOf(typeof(ApplicationException)))
            {
                System.Windows.Forms.MessageBox.Show
                    (ex.Message, "提示！"
                    , System.Windows.Forms.MessageBoxButtons.OK
                    , System.Windows.Forms.MessageBoxIcon.Warning);
            }
            else
            {
                System.Windows.Forms.MessageBox.Show
                    (ex.Message + "\r\n\r\n" + ex.StackTrace, "系统错误！"
                    , System.Windows.Forms.MessageBoxButtons.OK
                    , System.Windows.Forms.MessageBoxIcon.Error);
            }
        }
    }
}
